<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style></style>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="item in list">
          <input type="checkbox" :value="item" v-model="res" /> {{item}}
        </li>
      </ul>
      <div>
        <label>
          <input
            type="checkbox"
            :checked="res.length==list.length&&list.length"
            @change="change"
          />全选
        </label>
        <button @click="list=list.filter(item=>!res.includes(item)),res=[]">
          删除所选
        </button>
      </div>
      {{res}}
    </div>
  </body>
  <script>
    let app = Vue.createApp({
      data() {
        return {
          list: ["苹果", "西瓜", "香蕉", "火龙果"],
          res: [],
        };
      },
      methods: {
        change(e) {
          // 勾选
          if (e.target.checked) {
            this.res = [...this.list];
          } else {
            // 取消
            this.res = [];
          }
        },
      },
    });
    app = app.mount("#app");
  </script>
</html>
